package com.tony.study.thread;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: StacticProxy
 * @Auther: 皮蛋布丁
 * @Date: 2021/10/30/22:33
 * @Description: 静态代理模式
 * 静态代理模式总结：真实对象和代理对象都要实现同一个接口；代理对象要代理真实角色
 * 好处：代理对象可以做很多真实对象做不了的事情；真实对象专注于做自己的事情
 */
public class StacticProxy {

    public static void main(String[] args) {
        /*You you = new You();    //你结婚
        WeddingCompany weddingCompany = new WeddingCompany(you);
        weddingCompany.HappyMarry();*/

        new Thread(() -> System.out.println("我爱你")).start();

        new WeddingCompany(new You()).HappyMarry();
    }
}

interface Marray {
    //人间四大喜事：久旱逢甘霖、他乡遇故知、洞房花烛夜、金榜题名时
    void HappyMarry();
}

//真是角色，你去结婚
class You implements Marray {

    @Override
    public void HappyMarry() {
        System.out.println("老朱要结婚了，超级开心！");
    }
}

//代理角色，帮助你去结婚
class WeddingCompany implements Marray {

    private Marray target;  //代理谁-->真实目标角色

    public WeddingCompany(Marray target) {
        this.target = target;
    }

    @Override
    public void HappyMarry() {
        before();
        this.target.HappyMarry();   //这是真实对象
        after();
    }

    private void before() {
        System.out.println("结婚之前，布置现场");
    }

    private void after() {
        System.out.println("结婚之后，收份子钱");
    }
}